<?php

class Silk_Mapi_Model_Api2_Shipping_Orders_Rest_Admin_V1 extends Silk_Mapi_Model_Api2_Shipping_Orders_Rest
{
    public function _update()
    {
        $this->canComplete();

        if ($this->_getItemData()) {
            $this->createCreditmemo();
        }

        try {
            $this->orderComplete();
        } catch (Exception $e) {
            //$this->deleteCreditmemo();
            $this->_critical($e->getMessage(), $e->getCode());
        }

        return array();
    }

    /**
     * @param Mage_Sales_Model_Order $order
     * @return Mage_Core_Model_Abstract
     */
    protected function _initCredimemoInvoice(Mage_Sales_Model_Order $order)
    {
        $invoice = Mage::getModel('sales/order_invoice')->load($order->getId(), 'order_id');
        if ($invoice && $invoice->getId()) {
            return $invoice;
        }
        $this->_critical('订单还未打印！', Mage_Api2_Model_Resource::ERROR_UNKNOWN_ERROR);
    }
}
